<style lang="less">
  #div_create_truck_load_driver_dialog_sy {
  }
</style>
<template>
  <div id="div_create_truck_load_driver_dialog_sy">
    <el-dialog :visible.sync="isShow" width="40%">
      <el-form ref="modelForm" :model="modelForm" label-width="110px">
        <el-form-item prop="driverName" label="司机姓名" :rules="{ required: true, message: '请输入司机姓名', trigger: 'change' }">
          <el-input v-model="modelForm.driverName"></el-input>
        </el-form-item>
        <el-form-item prop="driverPhone" label="联系手机"
                      :rules="[{ required: true, message: '请输入联系手机', trigger: 'change' },
                      { len: 11, message: '手机号请控制在11位', trigger: 'change' }]">
          <el-input type="number" v-model="modelForm.driverPhone"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="createClick">保 存</el-button>
          <el-button @click="isShow = false">取 消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import { resetForm } from '../../lib/util.js';
import md5 from 'js-md5';
import { saveTruckLoadDriver } from '../../api/v3/TruckLoadDriver.js';

export default {
  props: {
    truckLoadDriverModel: {}
  },
  watch: {
    truckLoadDriverModel (val) {
      resetForm(this.$refs.modelForm, this.modelForm);
      let model = JSON.parse(val);
      this.isShow = model.isShow;
    }
  },
  data () {
    return {
      isShow: false,
      modelForm: {}
    };
  },
  methods: {
    createClick () {
      this.$refs['modelForm'].validate(modelFormValid => {
        if (modelFormValid) {
          let o = this.modelForm;
          o.password = md5('lmsy56');
          o.account = o.driverPhone;
          o.createDate = new Date();
          o.orgIds = this.$store.state.currentOrganizationId;
          o.driverStatus = 111002002;
          o.driverStatusName = '禁用';
          saveTruckLoadDriver(o).then((res) => {
            this.isShow = false;
            this.$emit('isRefresh', true);
          });
        }
      });
    }
  },
  mounted () {}
};
</script>
